import 'package:catguard/config/config.dart';
import 'package:catguard/routers/routers.dart';
import 'package:catguard/utils/singleton_manager.dart';
import 'package:catguard/utils/theme_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';

import 'global/global_data.dart';
import 'language.dart';

class Application extends StatelessWidget {
  const Application({super.key});

  getCurrentLanguage(){
    switch (SingletonManager().appLanguage) {
      case 'zh_TW':
        return const Locale("zh", "TW");
      case 'zh_CN':
        return const Locale("zh", "CN");
      case 'en_US':
        return const Locale("en", "US");
    }
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(750, 1500),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return GetMaterialApp(
          title: 'CatGuard',
          getPages: Routes.getPages,
          initialRoute: Routes.splash,
          locale: getCurrentLanguage(),
          fallbackLocale: const Locale("zh", "CN"),
          translations: LanguageMsg(),
          initialBinding: GlobalBinding(),
          theme: ThemeData(
            primarySwatch: createMaterialColor(Config.colorMain),
            primaryColor: Config.colorMain,
            // highlightColor: Colors.transparent, // 取消高亮效果
            splashColor: Colors.transparent,   // 取消水波纹效果
            // fontFamily: 'PingFangMedium',
            appBarTheme: AppBarTheme(
                backgroundColor: Config.colorBg,
                iconTheme: const IconThemeData(color: Config.colorText1),
                titleTextStyle: TextStyle(fontSize: Config.textSizeTitle.sp, color: Config.colorText1),
                elevation: 0),
          ),
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate, // 提供 Material 组件的中文文本
            GlobalWidgetsLocalizations.delegate, // 控制文本方向（如 RTL）
            GlobalCupertinoLocalizations.delegate, // iOS 风格组件本地化
          ],
          supportedLocales: const [
            Locale('zh', 'CN'), // 中文（简体）
            Locale('en', 'US'), // 英文（美国）
          ],
          builder: EasyLoading.init(),
        );
      },
    );
  }
}
